package com.web.controller;

import com.web.dto.UserInfoDTO;
import com.web.response.Result;
import com.web.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * @author yangguanzan
 * @date 9/23/21
 * @description
 */
@Controller
public class UserRegistController {

    @Autowired
    UserInfoService userInfoService;

    @GetMapping("regist")
    public String registPage(){
        return "regist";
    }

    @PostMapping("regist")
    public String registPage(ModelMap map,@ModelAttribute("user") UserInfoDTO userInfoDTO){

        //注册成功
        Result result = userInfoService.regist(userInfoDTO);
        if(result.isSuccess()){
            return "redirect:/login";
        }
        //注册失败
        map.addAttribute("result",result);
        return "regist";

    }

}
